USE [master]
GO
/****** Object:  Database [mundial]    Script Date: 05/18/2014 22:53:53 ******/
CREATE DATABASE [mundial] ON  PRIMARY 
( NAME = N'mundial', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mundial.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'mundial_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mundial_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [mundial] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [mundial].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [mundial] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [mundial] SET ANSI_NULLS OFF
GO
ALTER DATABASE [mundial] SET ANSI_PADDING OFF
GO
ALTER DATABASE [mundial] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [mundial] SET ARITHABORT OFF
GO
ALTER DATABASE [mundial] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [mundial] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [mundial] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [mundial] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [mundial] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [mundial] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [mundial] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [mundial] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [mundial] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [mundial] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [mundial] SET  DISABLE_BROKER
GO
ALTER DATABASE [mundial] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [mundial] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [mundial] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [mundial] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [mundial] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [mundial] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [mundial] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [mundial] SET  READ_WRITE
GO
ALTER DATABASE [mundial] SET RECOVERY FULL
GO
ALTER DATABASE [mundial] SET  MULTI_USER
GO
ALTER DATABASE [mundial] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [mundial] SET DB_CHAINING OFF
GO
EXEC sys.sp_db_vardecimal_storage_format N'mundial', N'ON'
GO
USE [mundial]
GO
/****** Object:  Table [dbo].[equipo]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[equipo](
	[idequipo] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[nombreEquipo] [varchar](50) NULL,
 CONSTRAINT [PK_equipo] PRIMARY KEY NONCLUSTERED 
(
	[idequipo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [IndexNombreEquipo] ON [dbo].[equipo] 
(
	[nombreEquipo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[usuario]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[usuario](
	[idUsuario] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[cedulaUsuario] [varchar](10) NOT NULL,
	[nombreUsuario] [varchar](50) NOT NULL,
	[apellidoUsuario] [varchar](100) NOT NULL,
	[nickName] [varchar](50) NOT NULL,
	[correoElectronico] [varchar](100) NOT NULL,
	[contrasena] [varchar](50) NOT NULL,
	[fechaCreacion] [datetime] NOT NULL,
	[numCuentaPSE] [varchar](100) NULL,
 CONSTRAINT [PK_usuario] PRIMARY KEY CLUSTERED 
(
	[idUsuario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY],
 CONSTRAINT [INDEXcedula] UNIQUE NONCLUSTERED 
(
	[cedulaUsuario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [indexCORREO] UNIQUE NONCLUSTERED 
(
	[correoElectronico] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY],
 CONSTRAINT [indexNickname] UNIQUE NONCLUSTERED 
(
	[nickName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[sala]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[sala](
	[idSala] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[nombreSala] [varchar](50) NOT NULL,
 CONSTRAINT [PK_sala] PRIMARY KEY NONCLUSTERED 
(
	[idSala] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[partido]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[partido](
	[idPartido] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[fechaPartido] [datetime] NOT NULL,
	[idequipoA] [int] NOT NULL,
	[idequipoB] [int] NOT NULL,
 CONSTRAINT [PK_partido] PRIMARY KEY NONCLUSTERED 
(
	[idPartido] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[mesa]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[mesa](
	[idMesa] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Monto] [money] NOT NULL,
	[cuposDisponibles] [int] NULL,
    [estado] [varchar](50) NULL,
	[idSala] [int] NOT NULL,
	[idPartido] [int] NOT NULL,
 CONSTRAINT [PK_mesa] PRIMARY KEY NONCLUSTERED 
(
	[idMesa] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[apuesta]    Script Date: 05/18/2014 22:53:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[apuesta](
	[idApuesta] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[fechaApuesta] [datetime] NOT NULL,
	[idMesa] [int] NOT NULL,
	[idUsuario] [int] NOT NULL,
	[MarcadorEquipoA] [int] NOT NULL,
	[MarcadorEquipoB] [int] NOT NULL,
 CONSTRAINT [PK_apuesta] PRIMARY KEY NONCLUSTERED 
(
	[idApuesta] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Default [DF__usuario__fechaCr__0AD2A005]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[usuario] ADD  CONSTRAINT [DF__usuario__fechaCr__0AD2A005]  DEFAULT (getdate()) FOR [fechaCreacion]
GO
/****** Object:  Default [DF__apuesta__fechaAp__0BC6C43E]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[apuesta] ADD  CONSTRAINT [DF__apuesta__fechaAp__0BC6C43E]  DEFAULT (getdate()) FOR [fechaApuesta]
GO

/****** Object:  ForeignKey [FK_partido_equipoA]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[partido]  WITH CHECK ADD  CONSTRAINT [FK_partido_equipoA] FOREIGN KEY([idequipoA])
REFERENCES [dbo].[equipo] ([idequipo])
GO
ALTER TABLE [dbo].[partido] CHECK CONSTRAINT [FK_partido_equipoA]
GO
/****** Object:  ForeignKey [FK_partido_partidoB]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[partido]  WITH CHECK ADD  CONSTRAINT [FK_partido_partidoB] FOREIGN KEY([idequipoB])
REFERENCES [dbo].[equipo] ([idequipo])
GO
ALTER TABLE [dbo].[partido] CHECK CONSTRAINT [FK_partido_partidoB]
GO
/****** Object:  ForeignKey [FK_mesa_partido]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[mesa]  WITH CHECK ADD  CONSTRAINT [FK_mesa_partido] FOREIGN KEY([idPartido])
REFERENCES [dbo].[partido] ([idPartido])
GO
ALTER TABLE [dbo].[mesa] CHECK CONSTRAINT [FK_mesa_partido]
GO
/****** Object:  ForeignKey [FK_mesa_sala]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[mesa]  WITH CHECK ADD  CONSTRAINT [FK_mesa_sala] FOREIGN KEY([idSala])
REFERENCES [dbo].[sala] ([idSala])
GO
ALTER TABLE [dbo].[mesa] CHECK CONSTRAINT [FK_mesa_sala]
GO
/****** Object:  ForeignKey [FK_apuesta_mesa]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[apuesta]  WITH CHECK ADD  CONSTRAINT [FK_apuesta_mesa] FOREIGN KEY([idMesa])
REFERENCES [dbo].[mesa] ([idMesa])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[apuesta] CHECK CONSTRAINT [FK_apuesta_mesa]
GO
/****** Object:  ForeignKey [FK_apuesta_usuario]    Script Date: 05/18/2014 22:53:55 ******/
ALTER TABLE [dbo].[apuesta]  WITH CHECK ADD  CONSTRAINT [FK_apuesta_usuario] FOREIGN KEY([idUsuario])
REFERENCES [dbo].[usuario] ([idUsuario])
GO
ALTER TABLE [dbo].[apuesta] CHECK CONSTRAINT [FK_apuesta_usuario]
GO
